package com.lanchetech.user.service.impl;


import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.util.PageHelpUtil;
import com.lanchetech.dao.ArticleMapper;
import com.lanchetech.dao.CompanyIntroductionMapper;
import com.lanchetech.entity.Article;
import com.lanchetech.entity.CompanyIntroduction;
import com.lanchetech.user.service.ArticleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    @Autowired
    CompanyIntroductionMapper companyIntroductionMapper;

    @Override
    public ResultData<Article> getArticle(Long id) {
        return new ResultData<>(articleMapper.selectByPrimaryKey(id));
    }

    @Override
    public ResultData<BasePageResp<Article>> getArticlePageByCatalog(PageReq req) {
        Page page = PageHelper.startPage(req.getPageNo(), req.getPageSize());
        List<Article> list = articleMapper.findAllByArticle(req);
        return PageHelpUtil.buildPage(list, page);
    }

    @Override
    public ResultData<Article> getEffectArticle(String effect) {
        return new ResultData<Article>(articleMapper.findOneByEffect(effect));
    }

    @Override
    public ResultData<CompanyIntroduction> getCompanyIntroduction() {
        return new ResultData<>(companyIntroductionMapper.selectByPrimaryKey(1L));
    }
}